{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import pickle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ASM</th>\n",
       "      <th>Mean</th>\n",
       "      <th>Standard deviation</th>\n",
       "      <th>area</th>\n",
       "      <th>class</th>\n",
       "      <th>contrast</th>\n",
       "      <th>convex_area</th>\n",
       "      <th>correlation</th>\n",
       "      <th>dissimilarity</th>\n",
       "      <th>eccentricity</th>\n",
       "      <th>energy</th>\n",
       "      <th>euler_number</th>\n",
       "      <th>extent</th>\n",
       "      <th>homogeneity</th>\n",
       "      <th>kurtosis</th>\n",
       "      <th>orientation</th>\n",
       "      <th>skew</th>\n",
       "      <th>solidity</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0.285761</td>\n",
       "      <td>68.329483</td>\n",
       "      <td>80.143673</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>649.131029</td>\n",
       "      <td>1</td>\n",
       "      <td>0.949574</td>\n",
       "      <td>6.389174</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.534566</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.644000</td>\n",
       "      <td>-1.026102</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>0.437733</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0.705255</td>\n",
       "      <td>20.817018</td>\n",
       "      <td>53.099576</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>513.964730</td>\n",
       "      <td>1</td>\n",
       "      <td>0.909389</td>\n",
       "      <td>4.205555</td>\n",
       "      <td>0.960659</td>\n",
       "      <td>0.839795</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.868637</td>\n",
       "      <td>18.922656</td>\n",
       "      <td>-0.692724</td>\n",
       "      <td>3.211472</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.199130</td>\n",
       "      <td>65.610310</td>\n",
       "      <td>69.660937</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1148.323650</td>\n",
       "      <td>1</td>\n",
       "      <td>0.881897</td>\n",
       "      <td>10.931032</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.446240</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.557320</td>\n",
       "      <td>1.464032</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>0.428516</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0.485445</td>\n",
       "      <td>32.539409</td>\n",
       "      <td>59.810339</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1172.741442</td>\n",
       "      <td>1</td>\n",
       "      <td>0.836718</td>\n",
       "      <td>10.137509</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.696739</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.742990</td>\n",
       "      <td>6.616861</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.119195</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.156314</td>\n",
       "      <td>71.760435</td>\n",
       "      <td>68.979068</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1211.991816</td>\n",
       "      <td>1</td>\n",
       "      <td>0.872515</td>\n",
       "      <td>11.240619</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.395366</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.528619</td>\n",
       "      <td>7.126889</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>-0.620239</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>0.463674</td>\n",
       "      <td>50.102691</td>\n",
       "      <td>84.501250</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1238.504372</td>\n",
       "      <td>1</td>\n",
       "      <td>0.913783</td>\n",
       "      <td>11.061152</td>\n",
       "      <td>0.790569</td>\n",
       "      <td>0.680936</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.711775</td>\n",
       "      <td>5.339253</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>1.564511</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>0.907863</td>\n",
       "      <td>4.988141</td>\n",
       "      <td>25.988603</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>172.607495</td>\n",
       "      <td>1</td>\n",
       "      <td>0.872368</td>\n",
       "      <td>1.554613</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.952818</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.958756</td>\n",
       "      <td>7.774738</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>1.405681</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>0.260564</td>\n",
       "      <td>70.583559</td>\n",
       "      <td>81.069658</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>842.722556</td>\n",
       "      <td>6</td>\n",
       "      <td>0.936146</td>\n",
       "      <td>8.949130</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.510454</td>\n",
       "      <td>1</td>\n",
       "      <td>0.555556</td>\n",
       "      <td>0.584418</td>\n",
       "      <td>1.142813</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>0.459309</td>\n",
       "      <td>0.833333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>0.573069</td>\n",
       "      <td>36.023047</td>\n",
       "      <td>73.131522</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>805.433210</td>\n",
       "      <td>1</td>\n",
       "      <td>0.925122</td>\n",
       "      <td>7.788582</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.757013</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.780964</td>\n",
       "      <td>10.373986</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.327461</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>0.633504</td>\n",
       "      <td>27.142666</td>\n",
       "      <td>61.111553</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>533.784332</td>\n",
       "      <td>1</td>\n",
       "      <td>0.929096</td>\n",
       "      <td>5.000503</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.795929</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.825971</td>\n",
       "      <td>9.395330</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.165754</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>0.261735</td>\n",
       "      <td>50.155227</td>\n",
       "      <td>63.147629</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1453.747638</td>\n",
       "      <td>1</td>\n",
       "      <td>0.818771</td>\n",
       "      <td>13.007935</td>\n",
       "      <td>0.985171</td>\n",
       "      <td>0.511601</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.608632</td>\n",
       "      <td>0.558993</td>\n",
       "      <td>0.392699</td>\n",
       "      <td>0.730281</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>0.074712</td>\n",
       "      <td>69.451484</td>\n",
       "      <td>64.199162</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3221.858235</td>\n",
       "      <td>1</td>\n",
       "      <td>0.605837</td>\n",
       "      <td>27.802803</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.273335</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.369646</td>\n",
       "      <td>0.162413</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>-0.301308</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>0.759811</td>\n",
       "      <td>13.884441</td>\n",
       "      <td>46.267787</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1132.556210</td>\n",
       "      <td>1</td>\n",
       "      <td>0.737879</td>\n",
       "      <td>8.292701</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.871671</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.881897</td>\n",
       "      <td>9.690550</td>\n",
       "      <td>-0.000000</td>\n",
       "      <td>2.362078</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>0.589494</td>\n",
       "      <td>30.934881</td>\n",
       "      <td>65.637766</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>801.299792</td>\n",
       "      <td>1</td>\n",
       "      <td>0.907853</td>\n",
       "      <td>7.110836</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.767785</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.800447</td>\n",
       "      <td>8.048518</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.631491</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>0.384479</td>\n",
       "      <td>48.080427</td>\n",
       "      <td>80.484196</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2133.200925</td>\n",
       "      <td>2</td>\n",
       "      <td>0.836730</td>\n",
       "      <td>17.714324</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.620064</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.656342</td>\n",
       "      <td>1.611123</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>1.470478</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>0.778703</td>\n",
       "      <td>10.491275</td>\n",
       "      <td>37.393469</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>843.009283</td>\n",
       "      <td>1</td>\n",
       "      <td>0.698083</td>\n",
       "      <td>6.545541</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.882442</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.895013</td>\n",
       "      <td>10.229401</td>\n",
       "      <td>-0.785398</td>\n",
       "      <td>2.633580</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>0.398255</td>\n",
       "      <td>56.224655</td>\n",
       "      <td>85.979169</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1399.588375</td>\n",
       "      <td>1</td>\n",
       "      <td>0.906245</td>\n",
       "      <td>12.259983</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.631074</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.685764</td>\n",
       "      <td>8.218121</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>1.575065</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>0.402345</td>\n",
       "      <td>48.683848</td>\n",
       "      <td>69.524410</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>515.753259</td>\n",
       "      <td>1</td>\n",
       "      <td>0.946691</td>\n",
       "      <td>5.891301</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.634306</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.690890</td>\n",
       "      <td>4.364555</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>1.486135</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>0.395407</td>\n",
       "      <td>67.114374</td>\n",
       "      <td>101.077298</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1072.195065</td>\n",
       "      <td>1</td>\n",
       "      <td>0.947650</td>\n",
       "      <td>9.931725</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.628814</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.769243</td>\n",
       "      <td>18.274050</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.308384</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>0.260539</td>\n",
       "      <td>67.178772</td>\n",
       "      <td>79.594214</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1045.079893</td>\n",
       "      <td>1</td>\n",
       "      <td>0.917961</td>\n",
       "      <td>10.319726</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.510430</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.581642</td>\n",
       "      <td>3.335164</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>0.947010</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>0.703406</td>\n",
       "      <td>19.260239</td>\n",
       "      <td>54.118630</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1107.358426</td>\n",
       "      <td>1</td>\n",
       "      <td>0.812929</td>\n",
       "      <td>7.760413</td>\n",
       "      <td>0.973723</td>\n",
       "      <td>0.838693</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.860563</td>\n",
       "      <td>17.806775</td>\n",
       "      <td>-1.079399</td>\n",
       "      <td>3.525976</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>0.910697</td>\n",
       "      <td>4.003498</td>\n",
       "      <td>24.207299</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>471.463513</td>\n",
       "      <td>3</td>\n",
       "      <td>0.571687</td>\n",
       "      <td>3.399559</td>\n",
       "      <td>0.816497</td>\n",
       "      <td>0.954304</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.958508</td>\n",
       "      <td>16.862082</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.573782</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>0.093249</td>\n",
       "      <td>91.542862</td>\n",
       "      <td>81.020293</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2710.330746</td>\n",
       "      <td>1</td>\n",
       "      <td>0.792945</td>\n",
       "      <td>23.096967</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.305368</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.385155</td>\n",
       "      <td>-1.115229</td>\n",
       "      <td>-0.000000</td>\n",
       "      <td>-0.179978</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>0.715277</td>\n",
       "      <td>15.166230</td>\n",
       "      <td>47.731062</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1202.503286</td>\n",
       "      <td>1</td>\n",
       "      <td>0.739104</td>\n",
       "      <td>9.086271</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.845741</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.861057</td>\n",
       "      <td>14.364030</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>3.259654</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>0.685366</td>\n",
       "      <td>13.870372</td>\n",
       "      <td>41.349537</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1111.537159</td>\n",
       "      <td>1</td>\n",
       "      <td>0.678296</td>\n",
       "      <td>8.619004</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.827868</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.853383</td>\n",
       "      <td>11.468612</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>3.258344</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>0.967529</td>\n",
       "      <td>1.939034</td>\n",
       "      <td>16.440156</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>76.477538</td>\n",
       "      <td>1</td>\n",
       "      <td>0.854898</td>\n",
       "      <td>0.710196</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.983631</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.984844</td>\n",
       "      <td>37.328373</td>\n",
       "      <td>-0.000000</td>\n",
       "      <td>4.812284</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>0.767611</td>\n",
       "      <td>13.882786</td>\n",
       "      <td>45.326397</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>676.987912</td>\n",
       "      <td>1</td>\n",
       "      <td>0.836882</td>\n",
       "      <td>5.436353</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.876134</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.889752</td>\n",
       "      <td>6.269088</td>\n",
       "      <td>-1.570796</td>\n",
       "      <td>1.902158</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>0.930175</td>\n",
       "      <td>2.462914</td>\n",
       "      <td>17.642670</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>206.902461</td>\n",
       "      <td>1</td>\n",
       "      <td>0.667864</td>\n",
       "      <td>1.704095</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.964456</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.970015</td>\n",
       "      <td>27.855153</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>4.023720</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>0.261620</td>\n",
       "      <td>68.575738</td>\n",
       "      <td>80.258912</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1070.372701</td>\n",
       "      <td>1</td>\n",
       "      <td>0.917187</td>\n",
       "      <td>9.589195</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.511488</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.603616</td>\n",
       "      <td>-1.250691</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>0.410181</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>0.902652</td>\n",
       "      <td>4.931866</td>\n",
       "      <td>26.000587</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>339.060142</td>\n",
       "      <td>2</td>\n",
       "      <td>0.698788</td>\n",
       "      <td>2.587353</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.950080</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.956115</td>\n",
       "      <td>-2.063368</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>0.330669</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>0.734374</td>\n",
       "      <td>13.271575</td>\n",
       "      <td>41.045604</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>764.440458</td>\n",
       "      <td>1</td>\n",
       "      <td>0.774556</td>\n",
       "      <td>6.075485</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.856956</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.877986</td>\n",
       "      <td>10.371450</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.732954</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>0.796651</td>\n",
       "      <td>8.850966</td>\n",
       "      <td>36.167901</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>744.449611</td>\n",
       "      <td>2</td>\n",
       "      <td>0.719489</td>\n",
       "      <td>5.844501</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.892553</td>\n",
       "      <td>1</td>\n",
       "      <td>0.500000</td>\n",
       "      <td>0.907006</td>\n",
       "      <td>9.479998</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>2.440652</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>0.556797</td>\n",
       "      <td>29.835254</td>\n",
       "      <td>67.609871</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>1915.346237</td>\n",
       "      <td>1</td>\n",
       "      <td>0.792155</td>\n",
       "      <td>14.092974</td>\n",
       "      <td>0.816497</td>\n",
       "      <td>0.746188</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.778298</td>\n",
       "      <td>6.931407</td>\n",
       "      <td>-1.570796</td>\n",
       "      <td>2.470876</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>0.417277</td>\n",
       "      <td>37.402680</td>\n",
       "      <td>62.858996</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1324.236072</td>\n",
       "      <td>1</td>\n",
       "      <td>0.833564</td>\n",
       "      <td>11.814829</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.645970</td>\n",
       "      <td>1</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>0.695718</td>\n",
       "      <td>3.726547</td>\n",
       "      <td>0.785398</td>\n",
       "      <td>1.598454</td>\n",
       "      <td>1.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         ASM       Mean  Standard deviation  area  class     contrast  \\\n",
       "0   0.285761  68.329483           80.143673     1      1   649.131029   \n",
       "1   0.705255  20.817018           53.099576     4      1   513.964730   \n",
       "2   0.199130  65.610310           69.660937     2      1  1148.323650   \n",
       "3   0.485445  32.539409           59.810339     1      1  1172.741442   \n",
       "4   0.156314  71.760435           68.979068     1      1  1211.991816   \n",
       "5   0.463674  50.102691           84.501250     4      1  1238.504372   \n",
       "6   0.907863   4.988141           25.988603     1      1   172.607495   \n",
       "7   0.260564  70.583559           81.069658     1      1   842.722556   \n",
       "8   0.573069  36.023047           73.131522     1      1   805.433210   \n",
       "9   0.633504  27.142666           61.111553     1      1   533.784332   \n",
       "10  0.261735  50.155227           63.147629     4      1  1453.747638   \n",
       "11  0.074712  69.451484           64.199162     1      1  3221.858235   \n",
       "12  0.759811  13.884441           46.267787     2      1  1132.556210   \n",
       "13  0.589494  30.934881           65.637766     1      1   801.299792   \n",
       "14  0.384479  48.080427           80.484196     1      1  2133.200925   \n",
       "15  0.778703  10.491275           37.393469     2      1   843.009283   \n",
       "16  0.398255  56.224655           85.979169     1      1  1399.588375   \n",
       "17  0.402345  48.683848           69.524410     1      1   515.753259   \n",
       "18  0.395407  67.114374          101.077298     1      1  1072.195065   \n",
       "19  0.260539  67.178772           79.594214     1      1  1045.079893   \n",
       "20  0.703406  19.260239           54.118630     3      1  1107.358426   \n",
       "21  0.910697   4.003498           24.207299     3      1   471.463513   \n",
       "22  0.093249  91.542862           81.020293     2      1  2710.330746   \n",
       "23  0.715277  15.166230           47.731062     1      1  1202.503286   \n",
       "24  0.685366  13.870372           41.349537     1      1  1111.537159   \n",
       "25  0.967529   1.939034           16.440156     2      1    76.477538   \n",
       "26  0.767611  13.882786           45.326397     2      1   676.987912   \n",
       "27  0.930175   2.462914           17.642670     1      0   206.902461   \n",
       "28  0.261620  68.575738           80.258912     1      0  1070.372701   \n",
       "29  0.902652   4.931866           26.000587     1      0   339.060142   \n",
       "30  0.734374  13.271575           41.045604     1      0   764.440458   \n",
       "31  0.796651   8.850966           36.167901     1      0   744.449611   \n",
       "32  0.556797  29.835254           67.609871     3      0  1915.346237   \n",
       "33  0.417277  37.402680           62.858996     1      0  1324.236072   \n",
       "\n",
       "    convex_area  correlation  dissimilarity  eccentricity    energy  \\\n",
       "0             1     0.949574       6.389174      0.000000  0.534566   \n",
       "1             1     0.909389       4.205555      0.960659  0.839795   \n",
       "2             1     0.881897      10.931032      1.000000  0.446240   \n",
       "3             1     0.836718      10.137509      0.000000  0.696739   \n",
       "4             1     0.872515      11.240619      0.000000  0.395366   \n",
       "5             1     0.913783      11.061152      0.790569  0.680936   \n",
       "6             1     0.872368       1.554613      0.000000  0.952818   \n",
       "7             6     0.936146       8.949130      0.000000  0.510454   \n",
       "8             1     0.925122       7.788582      0.000000  0.757013   \n",
       "9             1     0.929096       5.000503      0.000000  0.795929   \n",
       "10            1     0.818771      13.007935      0.985171  0.511601   \n",
       "11            1     0.605837      27.802803      0.000000  0.273335   \n",
       "12            1     0.737879       8.292701      1.000000  0.871671   \n",
       "13            1     0.907853       7.110836      0.000000  0.767785   \n",
       "14            2     0.836730      17.714324      0.000000  0.620064   \n",
       "15            1     0.698083       6.545541      1.000000  0.882442   \n",
       "16            1     0.906245      12.259983      0.000000  0.631074   \n",
       "17            1     0.946691       5.891301      0.000000  0.634306   \n",
       "18            1     0.947650       9.931725      0.000000  0.628814   \n",
       "19            1     0.917961      10.319726      0.000000  0.510430   \n",
       "20            1     0.812929       7.760413      0.973723  0.838693   \n",
       "21            3     0.571687       3.399559      0.816497  0.954304   \n",
       "22            1     0.792945      23.096967      1.000000  0.305368   \n",
       "23            1     0.739104       9.086271      0.000000  0.845741   \n",
       "24            1     0.678296       8.619004      0.000000  0.827868   \n",
       "25            1     0.854898       0.710196      1.000000  0.983631   \n",
       "26            1     0.836882       5.436353      1.000000  0.876134   \n",
       "27            1     0.667864       1.704095      0.000000  0.964456   \n",
       "28            1     0.917187       9.589195      0.000000  0.511488   \n",
       "29            2     0.698788       2.587353      0.000000  0.950080   \n",
       "30            1     0.774556       6.075485      0.000000  0.856956   \n",
       "31            2     0.719489       5.844501      0.000000  0.892553   \n",
       "32            1     0.792155      14.092974      0.816497  0.746188   \n",
       "33            1     0.833564      11.814829      0.000000  0.645970   \n",
       "\n",
       "    euler_number    extent  homogeneity   kurtosis  orientation      skew  \\\n",
       "0              1  1.000000     0.644000  -1.026102     0.785398  0.437733   \n",
       "1              1  1.000000     0.868637  18.922656    -0.692724  3.211472   \n",
       "2              1  1.000000     0.557320   1.464032     0.785398  0.428516   \n",
       "3              1  1.000000     0.742990   6.616861     0.785398  2.119195   \n",
       "4              1  1.000000     0.528619   7.126889     0.785398 -0.620239   \n",
       "5              1  1.000000     0.711775   5.339253     0.785398  1.564511   \n",
       "6              1  1.000000     0.958756   7.774738     0.785398  1.405681   \n",
       "7              1  0.555556     0.584418   1.142813     0.785398  0.459309   \n",
       "8              1  1.000000     0.780964  10.373986     0.785398  2.327461   \n",
       "9              1  1.000000     0.825971   9.395330     0.785398  2.165754   \n",
       "10             1  1.000000     0.608632   0.558993     0.392699  0.730281   \n",
       "11             1  1.000000     0.369646   0.162413     0.785398 -0.301308   \n",
       "12             1  1.000000     0.881897   9.690550    -0.000000  2.362078   \n",
       "13             1  1.000000     0.800447   8.048518     0.785398  2.631491   \n",
       "14             1  1.000000     0.656342   1.611123     0.785398  1.470478   \n",
       "15             1  1.000000     0.895013  10.229401    -0.785398  2.633580   \n",
       "16             1  1.000000     0.685764   8.218121     0.785398  1.575065   \n",
       "17             1  1.000000     0.690890   4.364555     0.785398  1.486135   \n",
       "18             1  1.000000     0.769243  18.274050     0.785398  2.308384   \n",
       "19             1  1.000000     0.581642   3.335164     0.785398  0.947010   \n",
       "20             1  1.000000     0.860563  17.806775    -1.079399  3.525976   \n",
       "21             1  1.000000     0.958508  16.862082     0.785398  2.573782   \n",
       "22             1  1.000000     0.385155  -1.115229    -0.000000 -0.179978   \n",
       "23             1  1.000000     0.861057  14.364030     0.785398  3.259654   \n",
       "24             1  1.000000     0.853383  11.468612     0.785398  3.258344   \n",
       "25             1  1.000000     0.984844  37.328373    -0.000000  4.812284   \n",
       "26             1  1.000000     0.889752   6.269088    -1.570796  1.902158   \n",
       "27             1  1.000000     0.970015  27.855153     0.785398  4.023720   \n",
       "28             1  1.000000     0.603616  -1.250691     0.785398  0.410181   \n",
       "29             1  1.000000     0.956115  -2.063368     0.785398  0.330669   \n",
       "30             1  1.000000     0.877986  10.371450     0.785398  2.732954   \n",
       "31             1  0.500000     0.907006   9.479998     0.785398  2.440652   \n",
       "32             1  1.000000     0.778298   6.931407    -1.570796  2.470876   \n",
       "33             1  1.000000     0.695718   3.726547     0.785398  1.598454   \n",
       "\n",
       "    solidity  \n",
       "0   1.000000  \n",
       "1   1.000000  \n",
       "2   1.000000  \n",
       "3   1.000000  \n",
       "4   1.000000  \n",
       "5   1.000000  \n",
       "6   1.000000  \n",
       "7   0.833333  \n",
       "8   1.000000  \n",
       "9   1.000000  \n",
       "10  1.000000  \n",
       "11  1.000000  \n",
       "12  1.000000  \n",
       "13  1.000000  \n",
       "14  1.000000  \n",
       "15  1.000000  \n",
       "16  1.000000  \n",
       "17  1.000000  \n",
       "18  1.000000  \n",
       "19  1.000000  \n",
       "20  1.000000  \n",
       "21  1.000000  \n",
       "22  1.000000  \n",
       "23  1.000000  \n",
       "24  1.000000  \n",
       "25  1.000000  \n",
       "26  1.000000  \n",
       "27  1.000000  \n",
       "28  1.000000  \n",
       "29  1.000000  \n",
       "30  1.000000  \n",
       "31  1.000000  \n",
       "32  1.000000  \n",
       "33  1.000000  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ds = pd.read_csv('feature_all.csv', index_col=0)\n",
    "# drop feature that will not have impact \n",
    "# ds.drop(['solidity','euler_number' , 'extent'], 1 , inplace=True) \n",
    "ds"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "y = ds['class']\n",
    "classifier_f = open('Y_labels.pickle','wb')\n",
    "pickle.dump(y, classifier_f)\n",
    "classifier_f.close()    \n",
    "\n",
    "y\n",
    "# df1 = ds[['solidity','euler_number' , 'extent']]\n",
    "# df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/home/mu7ammad/anaconda2/lib/python2.7/site-packages/pandas/core/indexing.py:477: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  self.obj[item] = s\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ASM</th>\n",
       "      <th>Mean</th>\n",
       "      <th>Standard deviation</th>\n",
       "      <th>area</th>\n",
       "      <th>class</th>\n",
       "      <th>contrast</th>\n",
       "      <th>convex_area</th>\n",
       "      <th>correlation</th>\n",
       "      <th>dissimilarity</th>\n",
       "      <th>eccentricity</th>\n",
       "      <th>energy</th>\n",
       "      <th>homogeneity</th>\n",
       "      <th>kurtosis</th>\n",
       "      <th>orientation</th>\n",
       "      <th>skew</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.092141</td>\n",
       "      <td>2.624224</td>\n",
       "      <td>3.840221</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>1</td>\n",
       "      <td>0.939040</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>9.055433</td>\n",
       "      <td>1.083513</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>2.669151</td>\n",
       "      <td>3.858496</td>\n",
       "      <td>-0.124202</td>\n",
       "      <td>1.157596</td>\n",
       "      <td>0.338596</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2.695391</td>\n",
       "      <td>0.799487</td>\n",
       "      <td>2.544357</td>\n",
       "      <td>3.880245</td>\n",
       "      <td>1</td>\n",
       "      <td>0.743507</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>8.672212</td>\n",
       "      <td>0.713202</td>\n",
       "      <td>1.994929</td>\n",
       "      <td>4.193190</td>\n",
       "      <td>5.204400</td>\n",
       "      <td>2.290448</td>\n",
       "      <td>-1.021004</td>\n",
       "      <td>2.484145</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0.761049</td>\n",
       "      <td>2.519793</td>\n",
       "      <td>3.337922</td>\n",
       "      <td>1.940122</td>\n",
       "      <td>1</td>\n",
       "      <td>1.661177</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>8.410037</td>\n",
       "      <td>1.853747</td>\n",
       "      <td>2.076624</td>\n",
       "      <td>2.228128</td>\n",
       "      <td>3.339160</td>\n",
       "      <td>0.177210</td>\n",
       "      <td>1.157596</td>\n",
       "      <td>0.331467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.855307</td>\n",
       "      <td>1.249690</td>\n",
       "      <td>2.865914</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>1</td>\n",
       "      <td>1.696500</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>7.979204</td>\n",
       "      <td>1.719177</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.478897</td>\n",
       "      <td>4.451593</td>\n",
       "      <td>0.800922</td>\n",
       "      <td>1.157596</td>\n",
       "      <td>1.639244</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0.597412</td>\n",
       "      <td>2.755991</td>\n",
       "      <td>3.305250</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>1</td>\n",
       "      <td>1.753280</td>\n",
       "      <td>0.970061</td>\n",
       "      <td>8.320575</td>\n",
       "      <td>1.906249</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.974107</td>\n",
       "      <td>3.167200</td>\n",
       "      <td>0.862657</td>\n",
       "      <td>1.157596</td>\n",
       "      <td>-0.479769</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        ASM      Mean  Standard deviation      area  class  contrast  \\\n",
       "0  1.092141  2.624224            3.840221  0.970061      1  0.939040   \n",
       "1  2.695391  0.799487            2.544357  3.880245      1  0.743507   \n",
       "2  0.761049  2.519793            3.337922  1.940122      1  1.661177   \n",
       "3  1.855307  1.249690            2.865914  0.970061      1  1.696500   \n",
       "4  0.597412  2.755991            3.305250  0.970061      1  1.753280   \n",
       "\n",
       "   convex_area  correlation  dissimilarity  eccentricity    energy  \\\n",
       "0     0.970061     9.055433       1.083513      0.000000  2.669151   \n",
       "1     0.970061     8.672212       0.713202      1.994929  4.193190   \n",
       "2     0.970061     8.410037       1.853747      2.076624  2.228128   \n",
       "3     0.970061     7.979204       1.719177      0.000000  3.478897   \n",
       "4     0.970061     8.320575       1.906249      0.000000  1.974107   \n",
       "\n",
       "   homogeneity  kurtosis  orientation      skew  \n",
       "0     3.858496 -0.124202     1.157596  0.338596  \n",
       "1     5.204400  2.290448    -1.021004  2.484145  \n",
       "2     3.339160  0.177210     1.157596  0.331467  \n",
       "3     4.451593  0.800922     1.157596  1.639244  \n",
       "4     3.167200  0.862657     1.157596 -0.479769  "
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# compute mean and std for all class 1 samples\n",
    "# sample - (all feature samples std)\n",
    "\n",
    "ds_class_1 = ds[(ds['class' ] > 0)]\n",
    "\n",
    "ds_class_1.loc[0:,'Mean'] = (ds_class_1['Mean']) / ds_class_1['Mean'].std()\n",
    "ds_class_1.loc[0:,'ASM'] = (ds_class_1['ASM']  / ds_class_1['ASM'].std()) \n",
    "ds_class_1.loc[0:,'contrast'] = (ds_class_1['contrast']) / ds_class_1['contrast'].std()\n",
    "ds_class_1.loc[0:,'correlation'] = (ds_class_1['correlation']  /  ds_class_1['correlation'].std()) \n",
    "ds_class_1.loc[0:,'dissimilarity'] = (ds_class_1['dissimilarity'] / ds_class_1['dissimilarity'].std())\n",
    "ds_class_1.loc[0:,'energy'] = (ds_class_1['energy']  /  ds_class_1['energy'].std())\n",
    "ds_class_1.loc[0:,'kurtosis'] = (ds_class_1['kurtosis'] /  ds_class_1['kurtosis'].std())\n",
    "ds_class_1.loc[0:,'skew'] = (ds_class_1['skew']  / ds_class_1['skew'].std())\n",
    "ds_class_1.loc[0:,'Standard deviation'] = (ds_class_1['Standard deviation']  / ds_class_1['Standard deviation'].std())\n",
    "ds_class_1.loc[0:,'area'] = (ds_class_1['area']) / ds_class_1['area'].std()\n",
    "ds_class_1.loc[0:,'homogeneity'] = (ds_class_1['homogeneity']  / ds_class_1['homogeneity'].std()) \n",
    "ds_class_1.loc[0:,'orientation'] = (ds_class_1['orientation']  /  ds_class_1['orientation'].std()) \n",
    "ds_class_1.loc[0:,'convex_area'] = (ds_class_1['convex_area'] / ds_class_1['convex_area'].std())\n",
    "ds_class_1.loc[0:,'eccentricity'] = (ds_class_1['eccentricity'] /  ds_class_1['eccentricity'].std())\n",
    "\n",
    "ds_class_1.head()\n",
    "\n",
    "# old Version\n",
    "# ds_class_1['Mean'] = (ds_class_1['Mean'] - ds_class_1['Mean'].mean()) / ds_class_1['Mean'].std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ASM</th>\n",
       "      <th>Mean</th>\n",
       "      <th>Standard deviation</th>\n",
       "      <th>area</th>\n",
       "      <th>class</th>\n",
       "      <th>contrast</th>\n",
       "      <th>convex_area</th>\n",
       "      <th>correlation</th>\n",
       "      <th>dissimilarity</th>\n",
       "      <th>eccentricity</th>\n",
       "      <th>energy</th>\n",
       "      <th>homogeneity</th>\n",
       "      <th>kurtosis</th>\n",
       "      <th>orientation</th>\n",
       "      <th>skew</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>3.675442</td>\n",
       "      <td>0.103896</td>\n",
       "      <td>0.759560</td>\n",
       "      <td>1.322876</td>\n",
       "      <td>0</td>\n",
       "      <td>0.351665</td>\n",
       "      <td>2.04939</td>\n",
       "      <td>7.777457</td>\n",
       "      <td>0.367719</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.711422</td>\n",
       "      <td>6.987396</td>\n",
       "      <td>2.766757</td>\n",
       "      <td>0.881917</td>\n",
       "      <td>3.038178</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>1.033749</td>\n",
       "      <td>2.892825</td>\n",
       "      <td>3.455344</td>\n",
       "      <td>1.322876</td>\n",
       "      <td>0</td>\n",
       "      <td>1.819276</td>\n",
       "      <td>2.04939</td>\n",
       "      <td>10.680891</td>\n",
       "      <td>2.069208</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.028985</td>\n",
       "      <td>4.348078</td>\n",
       "      <td>-0.124227</td>\n",
       "      <td>0.881917</td>\n",
       "      <td>0.309714</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>3.566690</td>\n",
       "      <td>0.208048</td>\n",
       "      <td>1.119389</td>\n",
       "      <td>1.322876</td>\n",
       "      <td>0</td>\n",
       "      <td>0.576289</td>\n",
       "      <td>4.09878</td>\n",
       "      <td>8.137577</td>\n",
       "      <td>0.558313</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.626291</td>\n",
       "      <td>6.887265</td>\n",
       "      <td>-0.204947</td>\n",
       "      <td>0.881917</td>\n",
       "      <td>0.249677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30</th>\n",
       "      <td>2.901766</td>\n",
       "      <td>0.559853</td>\n",
       "      <td>1.767115</td>\n",
       "      <td>1.322876</td>\n",
       "      <td>0</td>\n",
       "      <td>1.299293</td>\n",
       "      <td>2.04939</td>\n",
       "      <td>9.019912</td>\n",
       "      <td>1.311000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.074820</td>\n",
       "      <td>6.324473</td>\n",
       "      <td>1.030161</td>\n",
       "      <td>0.881917</td>\n",
       "      <td>2.063564</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>3.147842</td>\n",
       "      <td>0.373372</td>\n",
       "      <td>1.557117</td>\n",
       "      <td>1.322876</td>\n",
       "      <td>0</td>\n",
       "      <td>1.265316</td>\n",
       "      <td>4.09878</td>\n",
       "      <td>8.378647</td>\n",
       "      <td>1.261158</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>5.285620</td>\n",
       "      <td>6.533516</td>\n",
       "      <td>0.941616</td>\n",
       "      <td>0.881917</td>\n",
       "      <td>1.842856</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>2.200098</td>\n",
       "      <td>1.258582</td>\n",
       "      <td>2.910772</td>\n",
       "      <td>3.968627</td>\n",
       "      <td>0</td>\n",
       "      <td>3.255448</td>\n",
       "      <td>2.04939</td>\n",
       "      <td>9.224852</td>\n",
       "      <td>3.041057</td>\n",
       "      <td>2.645751</td>\n",
       "      <td>4.418862</td>\n",
       "      <td>5.606383</td>\n",
       "      <td>0.688473</td>\n",
       "      <td>-1.763834</td>\n",
       "      <td>1.865677</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>1.648805</td>\n",
       "      <td>1.577809</td>\n",
       "      <td>2.706235</td>\n",
       "      <td>1.322876</td>\n",
       "      <td>0</td>\n",
       "      <td>2.250759</td>\n",
       "      <td>2.04939</td>\n",
       "      <td>9.707077</td>\n",
       "      <td>2.549467</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>3.825375</td>\n",
       "      <td>5.011526</td>\n",
       "      <td>0.370145</td>\n",
       "      <td>0.881917</td>\n",
       "      <td>1.206940</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         ASM      Mean  Standard deviation      area  class  contrast  \\\n",
       "27  3.675442  0.103896            0.759560  1.322876      0  0.351665   \n",
       "28  1.033749  2.892825            3.455344  1.322876      0  1.819276   \n",
       "29  3.566690  0.208048            1.119389  1.322876      0  0.576289   \n",
       "30  2.901766  0.559853            1.767115  1.322876      0  1.299293   \n",
       "31  3.147842  0.373372            1.557117  1.322876      0  1.265316   \n",
       "32  2.200098  1.258582            2.910772  3.968627      0  3.255448   \n",
       "33  1.648805  1.577809            2.706235  1.322876      0  2.250759   \n",
       "\n",
       "    convex_area  correlation  dissimilarity  eccentricity    energy  \\\n",
       "27      2.04939     7.777457       0.367719      0.000000  5.711422   \n",
       "28      2.04939    10.680891       2.069208      0.000000  3.028985   \n",
       "29      4.09878     8.137577       0.558313      0.000000  5.626291   \n",
       "30      2.04939     9.019912       1.311000      0.000000  5.074820   \n",
       "31      4.09878     8.378647       1.261158      0.000000  5.285620   \n",
       "32      2.04939     9.224852       3.041057      2.645751  4.418862   \n",
       "33      2.04939     9.707077       2.549467      0.000000  3.825375   \n",
       "\n",
       "    homogeneity  kurtosis  orientation      skew  \n",
       "27     6.987396  2.766757     0.881917  3.038178  \n",
       "28     4.348078 -0.124227     0.881917  0.309714  \n",
       "29     6.887265 -0.204947     0.881917  0.249677  \n",
       "30     6.324473  1.030161     0.881917  2.063564  \n",
       "31     6.533516  0.941616     0.881917  1.842856  \n",
       "32     5.606383  0.688473    -1.763834  1.865677  \n",
       "33     5.011526  0.370145     0.881917  1.206940  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# compute mean and std for all class( 0 )amples\n",
    "# sample - (all feature samples std\n",
    "\n",
    "ds_class_0= ds[(ds['class' ] < 1 )]\n",
    "\n",
    "ds_class_0.loc[0:,'Mean'] = (ds_class_0['Mean']) / ds_class_0['Mean'].std()\n",
    "ds_class_0.loc[0:,'ASM'] = (ds_class_0['ASM']  / ds_class_0['ASM'].std()) \n",
    "ds_class_0.loc[0:,'contrast'] = (ds_class_0['contrast']) / ds_class_0['contrast'].std()\n",
    "ds_class_0.loc[0:,'correlation'] = (ds_class_0['correlation']  /  ds_class_0['correlation'].std()) \n",
    "ds_class_0.loc[0:,'dissimilarity'] = (ds_class_0['dissimilarity'] / ds_class_0['dissimilarity'].std())\n",
    "ds_class_0.loc[0:,'energy'] = (ds_class_0['energy']  /  ds_class_0['energy'].std())\n",
    "ds_class_0.loc[0:,'kurtosis'] = (ds_class_0['kurtosis'] /  ds_class_0['kurtosis'].std())\n",
    "ds_class_0.loc[0:,'skew'] = (ds_class_0['skew']  / ds_class_0['skew'].std())\n",
    "ds_class_0.loc[0:,'Standard deviation'] = (ds_class_0['Standard deviation']  / ds_class_0['Standard deviation'].std())\n",
    "ds_class_0.loc[0:,'area'] = (ds_class_0['area']) / ds_class_0['area'].std()\n",
    "ds_class_0.loc[0:,'homogeneity'] = (ds_class_0['homogeneity']  / ds_class_0['homogeneity'].std()) \n",
    "ds_class_0.loc[0:,'orientation'] = (ds_class_0['orientation']  /  ds_class_0['orientation'].std()) \n",
    "ds_class_0.loc[0:,'convex_area'] = (ds_class_0['convex_area'] / ds_class_0['convex_area'].std())\n",
    "ds_class_0.loc[0:,'eccentricity'] = (ds_class_0['eccentricity'] /  ds_class_0['eccentricity'].std())\n",
    "ds_class_0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'ds_class_1' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-2-ff6c6e69b6a8>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[1;32m      1\u001b[0m \u001b[0;31m# concating all  features\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mframes\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0mds_class_1\u001b[0m \u001b[0;34m,\u001b[0m \u001b[0mds_class_0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m      3\u001b[0m \u001b[0mds_new\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconcat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mframes\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mignore_index\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m      4\u001b[0m \u001b[0mds_new\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_csv\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'Feature_all_optomized.csv'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
      "\u001b[0;31mNameError\u001b[0m: name 'ds_class_1' is not defined"
     ]
    }
   ],
   "source": [
    "# concating all  features\n",
    "frames = [ds_class_1 , ds_class_0]\n",
    "ds_new = pd.concat(frames, ignore_index=True)\n",
    "ds_new.to_csv('Feature_all_optomized.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  7.80227669e-02   4.93247634e-02   6.73377622e-02   3.87812490e-02\n",
      "   3.85950344e-03   2.42998184e-06   5.94999809e-02   3.44621575e-02\n",
      "   0.00000000e+00]\n",
      "1.55522222219\n"
     ]
    }
   ],
   "source": [
    "# feature selection with regression for texture feature only\n",
    "from sklearn.linear_model import Lasso\n",
    "\n",
    "df = pd.read_csv('brain-cancer.data')\n",
    "# replace (?) with -99999 in data set \n",
    "df.replace('?', -99999, inplace=True )\n",
    "# # remove  id colunm cause it has no effect in learning\n",
    "df.drop(['id'],1, inplace=True)\n",
    "feature = df.drop(['class'],1)\n",
    "labels =df['class'] \n",
    "classifier_f = open('n_y.pickle','wb')\n",
    "pickle.dump(labels, classifier_f)\n",
    "classifier_f.close()    \n",
    "regression = Lasso(alpha=0.1)\n",
    "regression.fit(feature, labels)\n",
    "# regression.predict([[0.62169290804739175,0.92176444484776776, 1]])\n",
    "print(regression.coef_)\n",
    "print(regression.intercept_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[-0.09523236 -0.04956931 -0.06734667]\n",
      "1.75573420055\n"
     ]
    }
   ],
   "source": [
    "# feature = df[['homogeneity', 'correlation','convex_area']]\n",
    "# labels =df['class'] \n",
    "# # print(labels)\n",
    "# print(feature)\n",
    "regression = Lasso(alpha=0.1)\n",
    "regression.fit(feature, labels)\n",
    "regression.predict([[0.62169290804739175,0.92176444484776776, 1]])\n",
    "print(regression.coef_)\n",
    "print(regression.intercept_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[  9.99999744e-01   1.78570205e-07]\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXYAAAD8CAYAAABjAo9vAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAHkJJREFUeJzt3WFsXNd55vH/S0qiSXdbqpashHIkWZtIBWl0nUKo0gqr\nFUIWcFvD7odF1lk5lds1WJPbVCkaBE71IdgPWizQbJEAqdVyHTduNEjaddNNEKStLbWEsEIsVI6F\ntJIsrsFaikWbohMpbSKZlsR3P8yMTA1nOPfOnDl35vL5AYI5h5dzzh1qHh+dOfe95u6IiEh+dGU9\nABERCUvBLiKSMwp2EZGcUbCLiOSMgl1EJGcU7CIiOaNgFxHJGQW7iEjOKNhFRHJmVRadrlu3zrds\n2ZJF1yIiHeull156y93X1zsuk2DfsmULJ0+ezKJrEZGOZWbnkxynpRgRkZxRsIuI5IyCXUQkZxTs\nIiI5o2AXE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s930zewx4EBj2ztq7eRF436LH95Ta\nOo6ZraYY6gV3/1rW42nALuAhM/sV4A7gJ83ssLt3Wpi8Drzu7uV/MT1HBwY7MAL8s7vPAZjZ14Bf\nBA5nOqrGzZrZe939DTN7L3Cp1R22/Yx9OWb2AMV/Pj/k7lezHk9K/wB8wMzuNbM1FD8c+kbGY0rN\nzIzimu5Zd//DrMfTCHf/tLvf4+5bKP4e/q4DQx13fxP4npltLzUNA2cyHFKjLgAfMrO+0t+vYTrw\nQ+BFvgHsK329D/h6qzts+xl7HV8AeoAXir9/XnT3J7IdUjLufsPMfhv4W4qf+j/j7qczHlYjdgEf\nA/7RzE6V2n7f3b+V4ZhWso8DhdJkYRr4jYzHk5q7nzCz54DvUFxifZkOuQLVzL4C7AHWmdnrwGeA\n/wH8hZn9F4pVbT/S8nF01uqFiIjU09FLMSIispSCXUQkZxTsIiI5o2AXEckZBbuISM4o2EVEckbB\nLiKSMwp2EZGc+f/9pkfO2LLc+QAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7fe6cde4b0d0>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# PCA\n",
    "from sklearn.decomposition import PCA , IncrementalPCA\n",
    "\n",
    "def do_pca(data):\n",
    "    pca = PCA(n_components=2)\n",
    "    pca.fit(data)\n",
    "    return pca\n",
    "\n",
    "data = np.array(feature)\n",
    "pca = do_pca(data)\n",
    "print(pca.explained_variance_ratio_)\n",
    "first_pc = pca.components_[0]\n",
    "second_pc = pca.components_[1]\n",
    "\n",
    "transformed_data = pca.transform(data)\n",
    "# fil = open(\"pca_trans_data.pickle\", 'wb')\n",
    "# pickle.dump( transformed_data, fil)\n",
    "# fil.close()\n",
    "\n",
    "for ii , jj in zip(transformed_data, data):\n",
    "    plt.scatter( first_pc[0] * ii[0], first_pc[1]*ii[0], color='r' )\n",
    "    plt.scatter( second_pc[0] * ii[1], second_pc[1]*ii[1], color='b' )\n",
    "    plt.scatter(jj[0], jj[1], color='c')\n",
    "    \n",
    "\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "IncrementalPCA(batch_size=None, copy=True, n_components=3, whiten=False)\n",
      "[ 0.43748164  0.30472306  0.23822362]\n"
     ]
    }
   ],
   "source": [
    "# IncrementalPCA\n",
    "ipca =  IncrementalPCA(n_components=3)\n",
    "print(ipca)\n",
    "ipca.fit(feature)\n",
    "x =ipca.transform(feature) \n",
    "print(ipca.explained_variance_ratio_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'batch_size': None, 'copy': True, 'n_components': 3, 'whiten': False}"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# ipca.get_covariance()\n",
    "ipca.get_precision()\n",
    "ipca.get_params(deep=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Gaussian random projection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[  1.41077893  -1.2972483   -1.07751863   0.77263765   0.84400981]\n",
      " [ -4.90712009  -3.1844581   -2.72473208   7.15423346  -3.60527062]\n",
      " [  0.43485394  -0.43889526  -0.82541805   1.19678383   0.79633641]\n",
      " ..., \n",
      " [ 11.30531959  -2.3013658    0.53556658   7.10337376  -6.1247155 ]\n",
      " [  6.97983086  -0.78569674  -3.0884124    7.94605818  -4.78154031]\n",
      " [  4.16263553  -1.55291019  -2.75221864   8.36268833  -8.16222221]]\n"
     ]
    }
   ],
   "source": [
    "from sklearn import random_projection\n",
    "\n",
    "transform  = random_projection.GaussianRandomProjection(n_components=5)\n",
    "feature_new = transform.fit_transform(feature)\n",
    "classifier_f = open('n_GaussianRandomProjection.pickle','wb')\n",
    "pickle.dump(feature_new, classifier_f)\n",
    "classifier_f.close()    \n",
    "print(feature_new)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(34, 2)"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# FeatureAgglomeration\n",
    "\n",
    "from sklearn.cluster import FeatureAgglomeration\n",
    "\n",
    "agglo = FeatureAgglomeration( n_clusters=2)\n",
    "\n",
    "agglo.fit(feature)\n",
    "X_reduced = agglo.transform(feature)\n",
    "# X_reduced\n",
    "agglo.n_components_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
